package com.ruoyi.hikvision.task;

import com.ruoyi.hikvision.domain.HikvisionDevice;
import com.ruoyi.hikvision.domain.HikvisionDownloadFace;
import com.ruoyi.hikvision.handler.DeviceHandler;
import com.ruoyi.hikvision.service.IHikvisionDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DeviceTasks {

    @Autowired
    private IHikvisionDeviceService hikvisionDeviceService;

    @Autowired
    private DeviceHandler deviceHandler;

    //@Scheduled(fixedRate = 1000) // 每5秒执行一次
    public void downloadTask() {
        //System.out.println("每5秒执行一次任务：" + System.currentTimeMillis());
        // 查询任务
        HikvisionDevice hikvisionDevice = new HikvisionDevice();
        List<HikvisionDevice> deviceList = hikvisionDeviceService.selectHikvisionDeviceList(hikvisionDevice);
        // 判断设备是否在工作中
        for (HikvisionDevice deviceInfo : deviceList) {

            deviceHandler.download(deviceInfo);
            /*
            Boolean lock = deviceHandler.getLock(deviceInfo.getDeviceNo());
            if (!lock) {
                deviceHandler.download(deviceInfo);
            }*/
        }
    }
}
